/*
This codefile contains functionality for both Serial-  
components, specified in the design report ("tussenrapport.doc").

Author:			Geert
Version: 		1
Last modified:	09-06-11
*/

unsigned char Serial_welcome[53] = "Remote Lift C applicatie 2011 van groep1 (TI12/TI3a).";

// initializing function for this component
void Serial_Initialize ()
{
	char ch;
	
	// initialize the UART1 interrupt controller
	ICR13 &= 0xF8; // interrupt controller 13 (UART1 receive): set interrupt level to 0 (highest)
	
	// initialize UART 1
	SMR1_SOE 	= ON; // output enable
	SMR1_SCKE 	= OFF;
	SMR1_CS0 	= ON; // baud rate generator, 9600 Baud
	SMR1_CS1 	= ON;
	SMR1_CS2 	= OFF;
	SMR1_MD0 	= OFF; // Normal asynchronous mode
	SMR1_MD1 	= OFF;
	CDCR1_DIV0 	= OFF; // set prescaler to division by 1
	CDCR1_DIV1 	= OFF;
	CDCR1_DIV2 	= OFF;
	CDCR1_DIV3 	= OFF;
	CDCR1_MD 	= ON; // enable communication prescaler
	SCR1_TXE 	= ON; // Transmit enable
	SCR1_RXE 	= ON; // receive enable
	SCR1_REC 	= OFF; // clear error flags in SSR
	SCR1_AD 	= OFF;
	SCR1_CL 	= ON; // 8 data bits
	SCR1_SBL 	= OFF; // 1 stop bit
	SCR1_P 		= OFF; // even parity
	SCR1_PEN 	= OFF; // parity disable

	// Output welcome string and some spacing.
	Serial_Putch(10);
	Serial_Putch('t');
	Serial_Putch('e');
	Serial_Putch('s');
	Serial_Putch('t');
	Serial_Putch(10);
	Serial_Puts(Serial_welcome);
	Serial_Putch(10);
	Serial_Putch(10);
	Serial_Putch(10);
	Serial_Putch(13);
	
	// do the echo stuff for testing
	while(0)		
	{		
		ch = Serial_Getch();  
		Serial_Putch(ch);    	
		if (ch==13)	
			Serial_Putch(10);
		if (ch=='a')
			Serial_Putch('b');
	}
}